let express = require('express'); //引入express模块
let Mock = require('mockjs'); //引入mock模块

let app = express(); //实例化express

/*为app添加中间件处理跨域请求*/
app.use(function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header('Access-Control-Allow-Headers', 'Content-Type');
    next();
});

app.all('/sxgw/', function (req, res) {
    /**
    * mockjs中属性名‘|’符号后面的属性为随机属性，数组对象后面的随机属性为随机数组数量，正则表达式表示随机规则，+1代表自增
    */
    res.json(Mock.mock({
        "status": 200,
        "data|1-9": [{
            "name|5-8": /[a-zA-Z]/,
            "id|+1": 1,
            "value|0-500": 20
        }]
    }));
});


app.get('/sxgw/home_page/getCarousel', function (req, res) {
    /**
    * mockjs中属性名‘|’符号后面的属性为随机属性，数组对象后面的随机属性为随机数组数量，正则表达式表示随机规则，+1代表自增
    */
    res.json(Mock.mock({
        "success": true,
        "code": 200,
        "message": "成功",
        "data": {
            "list|4": [
                {
                    "id|+1": 0,
                    "level|+1": 1,
                    "picture|1": ["https://img11.360buyimg.com/da/jfs/t4000/107/2234194410/85271/6c24d985/58a50cafNb60886c9.jpg",
                    "https://img20.360buyimg.com/da/jfs/t3154/175/5917485830/129679/f123634c/5897e6a2N83837dd2.jpg",
                    "https://img1.360buyimg.com/da/jfs/t3133/89/5984232745/66970/beaf615c/589ac9bcNe544a72e.jpg",
                    "https://img20.360buyimg.com/da/jfs/t3157/165/6117849901/102894/88bf53b8/589d67b6Ne8986a9e.jpg"],
                    "modelName": "上贤资讯",
                    "fileName": "HomePage",
                    "gmtCreate": "2021-02-02 01:20:16",
                    "createTime": '@datetime',
                }
            ]
        }

    }));
});


app.get('/sxgw/jx_hotview/getCarousel', function (req, res) {
    /**
    * mockjs中属性名‘|’符号后面的属性为随机属性，数组对象后面的随机属性为随机数组数量，正则表达式表示随机规则，+1代表自增
    */
    res.json(Mock.mock({
        "success": true,
        "code": 200,
        "message": "成功",
        "data": {
            "list|3": [
                {
                    "id|+1": 0,
                    "level|+1": 1,
                    "picture|1": ["https://img11.360buyimg.com/da/jfs/t4000/107/2234194410/85271/6c24d985/58a50cafNb60886c9.jpg",
                    "https://img20.360buyimg.com/da/jfs/t3154/175/5917485830/129679/f123634c/5897e6a2N83837dd2.jpg",
                    "https://img1.360buyimg.com/da/jfs/t3133/89/5984232745/66970/beaf615c/589ac9bcNe544a72e.jpg"],
                    "modelName": "上贤资讯",
                    "fileName": "HomePage",
                    "gmtCreate": "2021-02-02 01:20:16",
                    "createTime": '@datetime',
                }
            ]
        }

    }));
});



/**
* 监听8090端口
*/
app.listen('8090');

console.log('运行成功');